package ylsb.service;


import org.springframework.stereotype.Service;
import ylsb.dao.DictShiyongyuanzeMapper;
import ylsb.dao.YiyongyuanzeMapper;
import ylsb.model.*;

import javax.annotation.Resource;
import java.util.List;

@Service
public class YiyongyuanzeService {

    @Resource
    YiyongyuanzeMapper ddMapper;

    public List<Yiyongyuanze> findOne(String pppinzhong, String pppinpai,
                                      String ppxiangmuid, String ppuserid){
        YiyongyuanzeExample mmExample=new YiyongyuanzeExample();
        mmExample.createCriteria().andPinzhongEqualTo(Integer.parseInt(pppinzhong))
                .andPinpaiEqualTo(pppinpai).andXiangmuidEqualTo(ppxiangmuid).andUseridEqualTo(ppuserid);
        return  ddMapper.selectByExample(mmExample);
    }
    public Yiyongyuanze checkexistBydetailanduserId(String ppId, String ppuserId){
        YiyongyuanzeExample mmExample=new YiyongyuanzeExample();
        YiyongyuanzeExample.Criteria criteria = mmExample.createCriteria();
        criteria.andDetailidEqualTo(ppId).andUseridEqualTo(ppuserId);
        return ddMapper.selectByExample(mmExample).size()>0? ddMapper.selectByExample(mmExample).get(0):
                null;
    }
    public Yiyongyuanze checkexistByUserId(String ppdetailid,int pppinzhong, String pppinpai,
                                           String ppuserid, String ppxiangmuId){
        YiyongyuanzeExample mmExample=new YiyongyuanzeExample();
        YiyongyuanzeExample.Criteria criteria = mmExample.createCriteria();
        criteria.andDetailidEqualTo(ppdetailid).andPinzhongEqualTo(pppinzhong).andPinpaiEqualTo(pppinpai).andXiangmuidEqualTo(ppxiangmuId)
                .andUseridEqualTo(ppuserid);
        return ddMapper.selectByExample(mmExample).size()>0? ddMapper.selectByExample(mmExample).get(0):
                null;
    }
    public Yiyongyuanze checkByUserId(int pppinzhong, String pppinpai,
                                           String ppuserid, String ppxiangmuId){
        YiyongyuanzeExample mmExample=new YiyongyuanzeExample();
        YiyongyuanzeExample.Criteria criteria = mmExample.createCriteria();
        criteria.andPinzhongEqualTo(pppinzhong).andPinpaiEqualTo(pppinpai).andXiangmuidEqualTo(ppxiangmuId)
                .andUseridEqualTo(ppuserid);
        return ddMapper.selectByExample(mmExample).size()>0? ddMapper.selectByExample(mmExample).get(0):
                null;
    }
    public boolean modify(Yiyongyuanze yiyongyuanze){return ddMapper.updateByPrimaryKeySelective(yiyongyuanze)==1;}

    public boolean add(Yiyongyuanze yiyongyuanze){
        return ddMapper.insert(yiyongyuanze)==1;
    }

    public boolean delete(String ppId){
        return ddMapper.deleteByPrimaryKey(ppId)==1;
    }

}
